﻿using UnityEngine;
using System.Collections;
using System;
using Assets.MatchVS;
using LitJson;

public class Setting : MonoBehaviour {
    UILabel time;
    UILabel history;
    // Use this for initialization
    void Start () {
        time = transform.Find("Time").gameObject.GetComponentInChildren<UILabel>();
        history = transform.Find("History").gameObject.GetComponentInChildren<UILabel>();
        refresHistory();
        UIUtil.setListener("BtnCustomStore", onclick);
    }

    private void refresHistory() {
        Http.hashGet(this, (text, err) => {
            JsonData data = JsonMapper.ToObject(text);
            //www on response->{"code":0,"data":"8/3/2016 6:44:47 PM","status":0} 
            history.text = "上次储存日期:"+data["data"].ToString();
        }, MatchVS.appkey, MatchVS.token, MatchVS.userID, MatchVS.gameID, MatchVS.key);
    }

    public void onclick(GameObject o) {
        Http.hashSet(this, (text, err) => {
            refresHistory();
        }, MatchVS.appkey, MatchVS.token, MatchVS.userID, MatchVS.gameID, MatchVS.key, DateTime.Now.ToString());
    }
	// Update is called once per frame
	void Update () {
        time.text = DateTime.Now.ToString();
    }
}
